<?php

namespace app\common\model;

use app\common\basic\BaseModel;
use app\enum\DealerAssistanceApplicationStatus;

class DealerAssistanceApplication extends BaseModel
{
    protected $table = 'vk_dealer_assistance_application';
    protected $append = ['apply_status_txt', 'loan_cycle_txt'];

    public function getApplyStatusTxtAttr($value, $data)
    {
        $map = DealerAssistanceApplicationStatus::toSelect();
        $map = array_column($map, 'label', 'value');
        return $map[$data['apply_status']] ?? '未知';
    }

    public function getLoanCycleTxtAttr($value, $data)
    {
        $map = [
            1 => '三个月',
            2 => '六个月',
            3 => '一年',
        ];
        return $map[$data['loan_cycle']] ?? '未知';
    }

    public function company() {
        return $this->belongsTo(Company::class, 'company_id', 'id');
    }

    public function dealer() {
        return $this->belongsTo(Dealer::class, 'dealer_id', 'id');
    }
}